"""
工具函数：日志、配置加载、模型检查点工具
"""
import os
import json
import logging
from typing import Dict, Any


def setup_logging(level: str = "INFO"):
    """配置日志格式"""
    logging.basicConfig(
        level=getattr(logging, level.upper()),
        format="%(asctime)s | %(levelname)s | %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S",
    )


def load_json_config(path: str) -> Dict[str, Any]:
    """加载JSON配置文件"""
    with open(path, "r") as f:
        return json.load(f)


def ensure_dir(path: str):
    """确保目录存在"""
    os.makedirs(path, exist_ok=True)
